#include "PlaneShot_2.h"
#include "Bullet.h"
#include "CNumber.h"


PlaneShot_2::PlaneShot_2(void)
{
	_currentTime = 0 ;
	_currentTimeWave = 0;
	_numShoot = 0;
}


PlaneShot_2::~PlaneShot_2(void)
{
}

void PlaneShot_2::onEnter()
{
	PlaneShotStrategy::onEnter();
}

void PlaneShot_2::onExit()
{
	PlaneShotStrategy::onExit();
}

void PlaneShot_2::shoot(float dt)
{
	// Get bullets
	if (_currentTime < getWeapon()->getTimeDelay())
	{
		_currentTime += dt;
		return;
	}

	Weapon* _weapon = getWeapon();
	if (!_weapon)
		return;

	CCDictionary* extra = getWeapon()->getExtraData();
	if (extra)
	{
		if (_numShoot > dynamic_cast<CCNumber<int>*>(extra->objectForKey("NumberShot"))->getNumber() - 1)
		{
			if (_currentTimeWave > dynamic_cast<CCNumber<float>*>(extra->objectForKey("TimeWaveDelay"))->getNumber())
			{
				_numShoot = 0;
				_currentTimeWave = 0;
			} else
				_currentTimeWave += dt;
			return;
		}
	}
	
	CCArray* bullets = _weapon->addBullet();
	// Change direct bla bla. In this case,	no need to change
	for (int i = 0; i < bullets->count(); i++)
	{
		Bullet* bullet = dynamic_cast<Bullet*>(bullets->objectAtIndex(i));
		CCPoint bu1Pos = bullet->getPosition();
		CCPoint a = ccp(getOwner()->boundingBox().getMidX(), getOwner()->boundingBox().getMaxY()) + bu1Pos;
		bullet->setPosition(ccp(getOwner()->boundingBox().getMidX(), getOwner()->boundingBox().getMaxY()) + bu1Pos);
	}
	_currentTime = 0;
	_numShoot++;
}
